# !/usr/bin/env python
# -*- coding: utf-8 -*-
from django.shortcuts import HttpResponseRedirect
import json
from django.http import HttpResponse
from dj3.utils import tokenUtil
try:
    from django.utils.deprecation import MiddlewareMixin  # Django 1.10.x
except ImportError:
    MiddlewareMixin = object  # Django 1.4.x - Django 1.9.x


class SimpleMiddleware(MiddlewareMixin):
    def process_request(self, request):
        pass
        if request.path != '/user/login' :
            token=request.META.get("HTTP_X_TOKEN")
            # # print(token)
            # if token==None:
            #     dic = {}
            #     dic['code'] = "-1"
            #     dic['msg'] = "未登录"
            #     return HttpResponse(json.dumps(dic, ensure_ascii=False))
            # user=None
            # try:
            #     user=tokenUtil.get_username(token)
            # except:
            #     print("异常token")
            #
            # if user!=None:
            #     pass
            # else:
            #     dic = {}
            #     dic['code'] = "-1"
            #     dic['msg'] = "登录超时"
            #     return HttpResponse(json.dumps(dic, ensure_ascii=False))


